package com.mcx.modules.proto;

import com.mcx.modules.common.IProto;
import com.mcx.modules.common.MMO_DataStream;

import java.io.*;
import java.util.*;

/**
 * 服务器广播其他角色进入场景消息
 */
public class WorldMap_OtherRoleEnterProto implements IProto
{
    private static MMO_DataStream dataStream = new MMO_DataStream();

    @Override
    public short getProtoCode() { return 13005; }

    public Integer RoleId; //角色编号
    public String RoleNickName; //角色昵称
    public Integer RoleLevel; //角色等级
    public Integer RoleJobId; //角色职业编号
    public Integer RoleCurrMP; //当前魔法
    public Integer RoleMaxMP; //最大魔法
    public Integer RoleCurrHP; //当前血量
    public Integer RoleMaxHP; //最大血量
    public Float RolePosX; //角色坐标X
    public Float RolePosY; //角色坐标Y
    public Float RolePosZ; //角色坐标Z
    public Float RoleYAngle; //角色Y轴旋转

    public byte[] ToArray() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (DataOutputStream outputStream = new DataOutputStream(out)) {
            dataStream.outputStream = outputStream;
            dataStream.WriteShort(getProtoCode());
            dataStream.WriteInt(RoleId);
            dataStream.WriteUTF8String(RoleNickName);
            dataStream.WriteInt(RoleLevel);
            dataStream.WriteInt(RoleJobId);
            dataStream.WriteInt(RoleCurrMP);
            dataStream.WriteInt(RoleMaxMP);
            dataStream.WriteInt(RoleCurrHP);
            dataStream.WriteInt(RoleMaxHP);
            dataStream.WriteFloat(RolePosX);
            dataStream.WriteFloat(RolePosY);
            dataStream.WriteFloat(RolePosZ);
            dataStream.WriteFloat(RoleYAngle);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();    }
    public static WorldMap_OtherRoleEnterProto GetProto(byte[] buffer) {
        WorldMap_OtherRoleEnterProto proto = new WorldMap_OtherRoleEnterProto();
        try (DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(buffer))) {
            dataStream.inputStream = inputStream;
            proto.RoleId = dataStream.ReadInt();
            proto.RoleNickName = dataStream.ReadUTF8String();
            proto.RoleLevel = dataStream.ReadInt();
            proto.RoleJobId = dataStream.ReadInt();
            proto.RoleCurrMP = dataStream.ReadInt();
            proto.RoleMaxMP = dataStream.ReadInt();
            proto.RoleCurrHP = dataStream.ReadInt();
            proto.RoleMaxHP = dataStream.ReadInt();
            proto.RolePosX = dataStream.ReadFloat();
            proto.RolePosY = dataStream.ReadFloat();
            proto.RolePosZ = dataStream.ReadFloat();
            proto.RoleYAngle = dataStream.ReadFloat();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return proto;
    }
}